﻿using System.Collections.Generic;
using LitJson;
namespace CGF
{
    public class GlobalData
    {
        //在售设备列表
        /*
        "id":16,
        "type":1,
        "icon":"http://8.134.166.57/tiktok.png",
        "name":"Versão demo(7 dias)",
        "subtitle":"2%-3%\n(Limite: 1 unid.)",
        "price":50000,
        "period":7,
        "profit":2,
        "renew_profit":5,
        "desc":"permitindo que.....",
        "buy_max":1,
        "buy_level":0,
        "input1":"",
        "input2":"Brasil",
        "input3":"V.1",
        "input4":"NVIDIA-A30",
        "input5":"40",
        "input6":"",
        "created_at":"0001-01-01T00:00:00Z"
        */
        public static List<JsonData> allSellDevices;
        public static async CTask LoadAllSellDevices()
        {
            var res = await Network.Get("/v1/order/sell?limit=1000");
            JsonData devicesData = res.jsonData["data"]["goods"];
            allSellDevices = new List<JsonData>();
            Debug.Log($"在售设备数量：{devicesData.Count}");
            for (int i = 0; i < devicesData.Count; i++)
            {
                allSellDevices.Add(devicesData[i]);
            }
        }
        
        public static JsonData GetDeviceByShopId(int shopId)
        {
            for (int i = 0; i < allSellDevices.Count; i++)
            {
                if ((int)allSellDevices[i]["id"] == shopId)
                {
                    return allSellDevices[i];
                }
            }
            Debug.LogError($"{allSellDevices.ToJson2()} shopId:{shopId}");
            return null;
        }
    }
}